package com.sht.product.yuea.weixin.request;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public abstract class BaseRequest {
	protected String url;
	public BaseRequest(String url) {
		this.url = url;
	}
	public BaseRequest(String url,Map<String, String> urlPara) {
		this.url = this.url+generateUrlPara(urlPara);
	}
	public static String generateUrlPara(Map<String, String> urlPara) {
		StringBuffer urlBuffer=new StringBuffer();
		if (urlPara!=null&urlPara.size()>0) { 
			urlBuffer.append("?");
			Iterator<Entry<String, String>> paras= urlPara.entrySet().iterator();
			Entry<String, String> para;
			while (paras.hasNext()) {
				para=paras.next();
				urlBuffer.append(para.getKey()).append("=").append(para.getValue()).append("&");
			}
		}
		return urlBuffer.toString();
	}



	protected void setUrlPara(Map<String, String> urlPara) {
		/*Set<Entry<String, String>> paras=urlPara.entrySet();
		Iterator<Entry<String, String>> iterator =paras.iterator();
		Entry<String, String>temp;
		while (iterator.hasNext()) {
			temp=iterator.next();
			System.out.println(temp.getKey()+"=>"+temp.getValue());
			
		}*/
		init(this.url+generateUrlPara(urlPara));
	}
	protected abstract void init(String url);
}
